import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { ElNotification } from 'element-plus'
import { piniaData } from '@/store';//引入pinia状态管理

const routes: Array<RouteRecordRaw> = [
    {
        path: '/index',//首页
        name: 'index',
        component: () => import('../views/index.vue'),
        children: [
            {
                path: '/AgvAutoInfo',
                name: 'AgvAutoInfo',
                component: () => import('../views/AgvAutoInfo.vue'),
            },
            {
                path: '/AGVDepotManagement',
                name: 'AGVDepotManagement',
                component: () => import('../views/AGVDepotManagement.vue'),
            },
            {
                path: '/RollRoom',
                name: 'RollRoom',
                component: () => import('../views/RollRoom.vue'),
            },
            {
                path: '/DeviceStatus',
                name: 'DeviceStatus',
                component: () => import('../views/DeviceStatus.vue'),
            },
            {
                path: '/faultInfo',
                name: 'faultInfo',
                component: () => import('../views/faultInfo.vue'),
            },
            {
                path: '/:pathMatch(.*)',
                redirect: '/RollRoom'
            }
        ]
    },
    {
        path: '/DataBoard',
        name: 'DataBoard',
        component: () => import('../views/DataBoard.vue'),
    },
    { path: '/', redirect: '/RollRoom' },
    {
        path: '/login',//登录
        name: 'login',
        component: () => import('../views/login.vue')
    }

]

const router = createRouter({
    history: createWebHashHistory(),
    routes
})

// // 路由全局守卫：登录拦截 本地没有用户信息, 请重新登录
// router.beforeEach((to, from, next) => {
//     const store = piniaData()
//     // 判断有没有登录
//     if (!store.userInfo) {
//         if (to.name == "login") {
//             next();
//         } else {
//             ElNotification({
//                 message: '请先登录！',
//                 type: 'error',
//             })
//             router.push('/')
//         }
//     } else {
//         //七天登录有效期设置
//         let loginTime: any = localStorage.getItem("loginTime");
//         let nowTime: any = String(Date.now());
//         let intervalTime: any = nowTime - loginTime;
//         //时间戳大小-------十秒：10000；一分钟：60000；七天：604800000
//         if (intervalTime >= 691200000) {
//             //清空控制登录状态的相关数据，并且跳转页面
//             store.userInfo = null
//             ElNotification({
//                 message: '请先登录！',
//                 type: 'error',
//             })
//             router.push('/')
//         } else {
//             next();

//         }
//     }
// });

export default router